package com.yauchu.kegra.graph.traversers;

import java.util.ArrayList;
import java.util.Iterator;

import org.jgrapht.DirectedGraph;

import com.yauchu.kegra.graph.GraphNode;
import com.yauchu.kegra.graph.NumberedEdge;
import com.yauchu.kegra.graph.OperatorNode;

public class ExpressionGenerator extends GraphNodeTraverser<String> {

	public ExpressionGenerator(DirectedGraph<GraphNode, NumberedEdge> graph) {
		super(graph);
	}

	protected String reduce(GraphNode current, ArrayList<String> res) {

		// String result_string = "";

		Iterator<String> it_str = res.iterator();

		if (current instanceof GraphNode) {
			//if (!(res.isEmpty())) 
			//{
				GraphNode operatorNode = (GraphNode) current;

				return operatorNode.operator.getExspression(it_str);
			//}
			//else
				//return "";
		} else {

			return current.getGenericStringRepresentation();
		}

	}

	public String getExpression(GraphNode rootNode, int depth) {

		return this.reduceInOrderDownToDepth(rootNode, depth);

	}
}
